package o;

import com.huawei.appgallery.assistantdock.buoydock.bean.GetGameBuoyEntryInfoResp;
import com.huawei.appgallery.assistantdock.buoydock.card.bean.BuoyLanternCardBeanBuoy;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.gamebox.framework.cardkit.bean.WiseJointDetailResponse;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

public class ezs {
    private static ezs ˋ;
    private Map<String, ezo> ˊ = new c(20, 0.25f, true);

    public static class c<K, V> extends LinkedHashMap<K, V> {
        public c(int i, float f, boolean z) {
            super(i, f, z);
        }

        protected boolean removeEldestEntry(Entry entry) {
            return size() > 20;
        }
    }

    public static synchronized ezs ˏ() {
        ezs o_ezs;
        synchronized (ezs.class) {
            if (ˋ == null) {
                ˋ = new ezs();
            }
            o_ezs = ˋ;
        }
        return o_ezs;
    }

    private ezs() {
    }

    public synchronized ezo ˋ(GameInfo gameInfo) {
        ezo o_ezo;
        if (gameInfo == null) {
            o_ezo = null;
        } else {
            o_ezo = ˎ(gameInfo.getAppId());
            if (o_ezo == null) {
                o_ezo = ˎ(gameInfo.getPackageName());
            }
        }
        return o_ezo;
    }

    private ezo ˎ(String str) {
        if (dof.ॱ(str)) {
            return null;
        }
        return (ezo) this.ˊ.get(str);
    }

    public synchronized void ˏ(GameInfo gameInfo, GetGameBuoyEntryInfoResp getGameBuoyEntryInfoResp) {
        String ˏ = ˏ(gameInfo);
        if (!dof.ॱ(ˏ)) {
            ezo o_ezo = (ezo) this.ˊ.get(ˏ);
            if (o_ezo == null) {
                o_ezo = new ezo();
                this.ˊ.put(ˏ, o_ezo);
            }
            o_ezo.ˊ(getGameBuoyEntryInfoResp);
        }
    }

    public synchronized void ˊ() {
        this.ˊ.clear();
    }

    private synchronized String ˏ(GameInfo gameInfo) {
        String str;
        if (gameInfo == null) {
            str = null;
        } else {
            str = gameInfo.getAppId();
            if (dof.ॱ(str)) {
                str = gameInfo.getPackageName();
            }
        }
        return str;
    }

    public void ॱ(GameInfo gameInfo, BaseRequest o_cvu, ResponseBean responseBean) {
        if ((responseBean instanceof WiseJointDetailResponse) && (o_cvu instanceof eyi) && gameInfo != null) {
            ezo ˋ = ˏ().ˋ(gameInfo);
            if (ˋ != null) {
                bgl ʼ = ˋ.ʼ();
                if (ʼ != null && ʼ.ˎ() != null && ʼ.ˎ().equals(((eyi) o_cvu).ˎ())) {
                    ˋ.ˏ(ˋ((WiseJointDetailResponse) responseBean));
                }
            }
        }
    }

    private BuoyLanternCardBeanBuoy ˋ(WiseJointDetailResponse wiseJointDetailResponse) {
        List<LayoutData> ᐝॱ = wiseJointDetailResponse.ᐝॱ();
        if (CollectCheck.isEmpty(ᐝॱ)) {
            Logger.ˋ("BuoyEntryInfoRepository", "analyseBuoyLantern, layoutdatas is empty");
            return null;
        }
        for (LayoutData layoutData : ᐝॱ) {
            if ("buoyentrancecard".equals(layoutData.ˏ())) {
                if (layoutData.ˋ() == null) {
                    Logger.e("BuoyEntryInfoRepository", "analyseBuoyLantern, layoutData.getDataList() == null");
                    return null;
                }
                ListIterator listIterator = layoutData.ˋ().listIterator(layoutData.ˋ().size());
                while (listIterator.hasPrevious()) {
                    BaseCardBean baseCardBean = (BaseCardBean) listIterator.previous();
                    if (baseCardBean instanceof BuoyLanternCardBeanBuoy) {
                        return (BuoyLanternCardBeanBuoy) baseCardBean;
                    }
                }
                continue;
            }
        }
        return null;
    }
}
